import {State} from '../src/state.js'
import {Coord} from '../src/coord.js'
import * as C from '../src/const.js'
import assert from 'assert'
import {Klotski} from "../src/klotski.js";

describe('Klotski', function() {
  describe('simple', function() {
    it('', function() {
      let m = new Map()
      m.set(C.T_MA, new Coord(0, 0))
      m.set(C.T_CAO, new Coord(1, 2))
      m.set(C.T_ZHAO, new Coord(3, 0))
      m.set(C.T_HUANG, new Coord(0, 2))
      m.set(C.T_ZHANG, new Coord(3, 2))
      m.set(C.T_GUAN, new Coord(1, 0))
      m.set(C.T_BING1, new Coord(0, 4))
      m.set(C.T_BING2, new Coord(1, 1))
      m.set(C.T_BING3, new Coord(2, 1))
      m.set(C.T_BING4, new Coord(1, 4))
      m.set(C.T_FREE1, new Coord(2, 4))
      m.set(C.T_FREE2, new Coord(3, 4))
      let klotski = new Klotski(m)
      let result = klotski.get_result()
      console.log(result)
      for (let r of result) {
        console.log(C.CHESS_MAP.get(r.index) + "" + C.D_MAP.get(r.direction) + "移")
      }
    })
  })

  describe('heng_dao_li_ma', function() {
    it('', function() {
      let m = new Map()
      m.set(C.T_MA, new Coord(0, 0))
      m.set(C.T_CAO, new Coord(1, 0))
      m.set(C.T_ZHAO, new Coord(3, 0))
      m.set(C.T_HUANG, new Coord(0, 2))
      m.set(C.T_ZHANG, new Coord(3, 2))
      m.set(C.T_GUAN, new Coord(1, 2))
      m.set(C.T_BING1, new Coord(0, 4))
      m.set(C.T_BING2, new Coord(1, 3))
      m.set(C.T_BING3, new Coord(2, 3))
      m.set(C.T_BING4, new Coord(3, 4))
      m.set(C.T_FREE1, new Coord(1, 4))
      m.set(C.T_FREE2, new Coord(2, 4))
      let klotski = new Klotski(m)
      let s = klotski.start
      let coord = s.get_coord(C.T_MA)
      assert.equal(coord.x, 0)
      assert.equal(coord.y, 0)
      coord = s.get_coord(C.T_CAO)
      assert.equal(coord.x, 1)
      assert.equal(coord.y, 0)
      coord = s.get_coord(C.T_ZHAO)
      assert.equal(coord.x, 3)
      assert.equal(coord.y, 0)
      coord = s.get_coord(C.T_HUANG)
      assert.equal(coord.x, 0)
      assert.equal(coord.y, 2)
      coord = s.get_coord(C.T_ZHANG)
      assert.equal(coord.x, 3)
      assert.equal(coord.y, 2)
      coord = s.get_coord(C.T_GUAN)
      assert.equal(coord.x, 1)
      assert.equal(coord.y, 2)
      coord = s.get_coord(C.T_BING1)
      assert.equal(coord.x, 0)
      assert.equal(coord.y, 4)
      coord = s.get_coord(C.T_BING2)
      assert.equal(coord.x, 1)
      assert.equal(coord.y, 3)
      coord = s.get_coord(C.T_BING3)
      assert.equal(coord.x, 2)
      assert.equal(coord.y, 3)
      coord = s.get_coord(C.T_BING4)
      assert.equal(coord.x, 3)
      assert.equal(coord.y, 4)
      coord = s.get_coord(C.T_FREE1)
      assert.equal(coord.x, 1)
      assert.equal(coord.y, 4)
      coord = s.get_coord(C.T_FREE2)
      assert.equal(coord.x, 2)
      assert.equal(coord.y, 4)
      let result = klotski.get_result()
      for (let i = 1; i < result.length; i++) {
        let step = result[i].get_step()
        console.log(i + "." + C.CHESS_MAP.get(step.index) + "" + C.D_MAP.get(step.direction) + "移")
      }
    })
  })
})